package com.learn.java3y.java.object;

import java.util.Date;

public class PersonTest {

    public static void main(String[] args) {
        Person person = new Person();
        person.setDate(new Date());
        try {
            Person p1 = (Person) person.clone();
            Thread.sleep(1000);
            p1.setDate(new Date()); // 修改了p1中的date，person中的date，也同步修改了
            System.out.println(p1);
            System.out.println(person);
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Person1 p2 = new Person1();
        p2.setDate(new Date());
        try {
            Person1 p3 = (Person1) p2.clone();
            Thread.sleep(1000);
            p2.setDate(new Date()); // 修改了p2中的date，p3中的date不修改
            System.out.println(p2);
            System.out.println(p3);
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}
